package hot100;

public class Solution02 {
    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        ListNode dummt = new ListNode(-1);
        ListNode cur = dummt;
        int count = 0;
        while (l1 != null || l2 != null) {
            int tmp1 = l1 == null ? 0 : l1.val;
            int tmp2 = l2 == null ? 0 : l2.val;
            count += tmp1 + tmp2;
            cur.next = new ListNode(count % 10);
            cur = cur.next;
            count /= 10;
            if (l1 != null) l1 = l1.next;
            if (l2 != null) l2 = l2.next;
        }
        if (count != 0) cur.next = new ListNode(count);
        return dummt.next;
    }
}

class ListNode {
    int val;
    ListNode next;

    ListNode() {
    }

    ListNode(int val) {
        this.val = val;
    }

    ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }
}